//
//  MyAssetCell.m
//  PigMarket
//
//  Created by mac on 2019/5/24.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "MyAssetCell.h"

@interface MyAssetCell ()
/**
 bg
 */
@property (nonatomic , strong) UIView *bgView;
/**
 icon
 */
@property (nonatomic , strong) UIImageView *icon;
/**
 iconTitle
 */
@property (nonatomic , strong) UILabel *iconTitle;
/**
 detail
 */
@property (nonatomic , strong) UILabel *detailInfo;
/**
 是否售完  过期
 */
@property (nonatomic , strong) UILabel *tipStatus;
/**
 箭头
 */
@property (nonatomic , strong) UIImageView *arrowImgView;
/**
 detailtoCheck
 */
@property (nonatomic , strong) UILabel *checkDetailInfoTip;

@end

@implementation MyAssetCell
+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString *identifierID = @"identifierID";
    MyAssetCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierID];
    if (cell == nil) {
        cell = [[MyAssetCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifierID];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor globalBackgroundColor];

    return cell;
}
#pragma mark - init method
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
        [self initLayout];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.icon];
    [self.bgView addSubview:self.iconTitle];
    [self.bgView addSubview:self.detailInfo];
    [self.bgView addSubview:self.tipStatus];
    [self.bgView addSubview:self.checkDetailInfoTip];
    [self.bgView addSubview:self.arrowImgView];
}

- (void)initLayout {
    // 布局子控件
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.bottom.mas_equalTo(0);
    }];
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(40);
        make.top.mas_equalTo(26);
        make.size.mas_equalTo(CGSizeMake(26, 26));
    }];
    [self.iconTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.icon.mas_centerX);
        make.top.mas_equalTo(self.icon.mas_bottom).offset(5);
        make.height.mas_equalTo(17);
    }];
    [self.detailInfo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(120);
        make.top.mas_equalTo(25);
        make.height.mas_equalTo(28);
    }];
    [self.tipStatus mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.detailInfo.mas_right).offset(10);
        make.top.mas_equalTo(33);
        make.height.mas_equalTo(17);
    }];
    [self.checkDetailInfoTip mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.detailInfo.mas_left);
        make.top.mas_equalTo(self.detailInfo.mas_bottom).offset(10);
        make.height.mas_equalTo(17);
    }];
    [self.arrowImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.checkDetailInfoTip.mas_right).offset(5);
        make.centerY.mas_equalTo(self.checkDetailInfoTip.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(12, 12));
    }];
}
- (void)configCellWithModel:(MyAsset *)model index:(NSIndexPath *)index {
    switch (index.row) {
        case 0:
        {
            self.icon.image = [UIImage imageNamed:@"user_myasset_money"];
            self.iconTitle.text = @"预售款";
            self.detailInfo.text = [NSString stringWithFormat:@"￥%@",model.saleMoney];
            self.tipStatus.text = [NSString stringWithFormat:@"(%@)",model.saleTag];
            if ([model.saleTag isEqualToString:@"未预售"]) {
                self.tipStatus.textColor = [UIColor colorWithHexString:@"#F1925D"];
            } else if ([model.saleTag isEqualToString:@"已售完"]) {
                self.tipStatus.textColor = [UIColor colorWithHexString:@"#9460FB"];
            } else if ([model.saleTag isEqualToString:@"部分售完"]) {
                self.tipStatus.textColor = [UIColor primaryColor];
            }
            self.checkDetailInfoTip.text = @"详情请查看店铺账本";
        }
            break;
        case 1:
        {
            self.icon.image = [UIImage imageNamed:@"user_service_myadopted"];
            self.iconTitle.text = @"存栏猪只";
            self.detailInfo.text = [NSString stringWithFormat:@"%@(只)",model.adoptCount];
            self.tipStatus.hidden = YES;
            self.checkDetailInfoTip.text = @"详情请查看我的领养";

        }
            break;
        case 2:
        {
            self.icon.image = [UIImage imageNamed:@"user_service_coupon"];
            self.iconTitle.text = @"豚券";
            self.detailInfo.text = model.couponMoney;
            if (model.couponOverdate == 0) {
                self.tipStatus.hidden = YES;
            } else {
                self.tipStatus.text = [NSString stringWithFormat:@"将要过期%@元",model.couponOverdate];
            }
            self.checkDetailInfoTip.text = @"详情请查看我的豚券";
        }
            break;
        case 3:
        {
            self.icon.image = [UIImage imageNamed:@"user_myasset_buymeat"];
            self.iconTitle.text = @"买肉";
            self.detailInfo.text = [NSString stringWithFormat:@"%@(单)",model.orderCount];
            self.tipStatus.hidden = YES;
            self.checkDetailInfoTip.text = @"详情请查看我的订单";

        }
            break;
        case 4:
        {
            self.icon.image = [UIImage imageNamed:@"user_myasset_rewards"];
            self.iconTitle.text = @"奖金";
            self.detailInfo.text = [NSString stringWithFormat:@"￥%@",model.reward];
            self.tipStatus.hidden = YES;
            self.checkDetailInfoTip.text = @"详情请查看我的奖金";
        }
            break;
        default:
            break;
    }
}
#pragma mark - getter and setter
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
        _bgView.layer.cornerRadius = 8;
        _bgView.backgroundColor = [UIColor whiteColor];
        _bgView.layer.shadowColor = [UIColor colorWithRed:59/255.0 green:74/255.0 blue:116/255.0 alpha:0.35].CGColor;
        _bgView.layer.shadowOffset = CGSizeMake(0,2);
        _bgView.layer.shadowOpacity = 1;
        _bgView.layer.shadowRadius = 4;
    }
    return _bgView;
}
- (UIImageView *)icon {
    if (!_icon) {
        _icon = [[UIImageView alloc] init];
    }
    return _icon;
}
- (UILabel *)iconTitle {
    if (!_iconTitle) {
        _iconTitle = [[UILabel alloc] init];
        _iconTitle.textColor = [UIColor colorWithHexString:@"#666666"];
        _iconTitle.font = [UIFont smallFont];
    }
    return _iconTitle;
}
- (UILabel *)detailInfo {
    if (!_detailInfo) {
        _detailInfo = [[UILabel alloc] init];
        _detailInfo.textColor = [UIColor colorWithHexString:@"#333333"];
        _detailInfo.font = [UIFont systemFontOfSize:20];
    }
    return _detailInfo;
}
- (UILabel *)tipStatus {
    if (!_tipStatus) {
        _tipStatus = [[UILabel alloc] init];
        _tipStatus.font = [UIFont smallFont];
    }
    return _tipStatus;
}
- (UILabel *)checkDetailInfoTip {
    if (!_checkDetailInfoTip) {
        _checkDetailInfoTip = [[UILabel alloc] init];
        _checkDetailInfoTip.textColor = [UIColor colorWithHexString:@"#999999"];
        _checkDetailInfoTip.font = [UIFont smallFont];
    }
    return _checkDetailInfoTip;
}
- (UIImageView *)arrowImgView {
    if (!_arrowImgView) {
        _arrowImgView = [[UIImageView alloc] init];
        _arrowImgView.image = [UIImage imageNamed:@"user_gt"];
    }
    return _arrowImgView;
}
@end
